package com.shicijiaoliu.mapper;

import com.shicijiaoliu.pojo.Author;
import com.shicijiaoliu.pojo.User;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface Usermapper {
    @Select("select * from user where username = #{username}")
    User findByName(String username);

    void add(String username, String password, String email, String phone, String nickname ,LocalDateTime createTime,LocalDateTime updateTime,String ruler);

    @Update("update user set username=#{username},nickname=#{nickname},email=#{email},update_time=#{updateTime},ruler=#{ruler},phone=#{phone},sex =#{sex},age=#{age},hobby=#{hobby} where ID = #{id}")
    void update(User user);

    @Update("update user set password=#{newpwd},update_time=#{now} where ID=#{id}")
    void updatepwd(String newpwd, LocalDateTime now,long id);

    @Insert("insert into author(name,Bi,dynasty)" +
    " values (#{name},#{bi},#{dynasty})")
    void beauthor(Author author);

    int getcount(String username, String nickname);

    List<User> finduserBypage(String username, String nickname);
    
    @Select("select * from user where ID=#{id}")
    User findByid(long id);

    @Delete("delete from user where ID=#{id}")
    void deluser(long id);
    @Update("update user set user_pic=#{src},update_time=#{now} where ID=#{id}")
    void updateimg(String src,LocalDateTime now,long id);

    @Select("select * from user where email=#{email}")
    User findByEmail(String email);
}
